package com.jcl.recruit.corp.mapper;


import com.jcl.recruit.corp.model.Subcompany;
import com.jcl.core.utils.StringUtils;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

/**
 * @ClassName SubcompanyProvider

 * @Author yyliu
 * @Date 2018/9/12 16:48
 * @Version 1.0
 **/
public class SubcompanyProvider {

    public String insertSelective(Subcompany company){

        BEGIN();
        INSERT_INTO("subcompany");

        if(StringUtils.hasLength(company.getAddress())){
            VALUES("address", "#{address, jdbcType=VARCHAR}");
        }
        if(StringUtils.hasLength(company.getCode())){
            VALUES("code", "#{code, jdbcType=VARCHAR}");
        }
        if(null != company.getComNature()){
            VALUES("com_nature", "#{comNature, jdbcType=INTEGER}");
        }
        if(null != company.getComSize()){
            VALUES("com_size", "#{comSize, jdbcType=INTEGER}");
        }
        if(StringUtils.hasLength(company.getEmail())){
            VALUES("email", "#{email, jdbcType=VARCHAR}");
        }
        if(StringUtils.hasLength(company.getFullname())){
            VALUES("fullname", "#{fullname, jdbcType=VARCHAR}");
        }

        if(StringUtils.hasLength(company.getIndustry())){
            VALUES("industry", "#{industry, jdbcType=VARCHAR}");
        }

        if(StringUtils.hasLength(company.getShortname())){
            VALUES("shortname", "#{shortname, jdbcType=VARCHAR}");
        }

        if(StringUtils.hasLength(company.getTelephone())){
            VALUES("telephone", "#{telephone, jdbcType=VARCHAR}");
        }
        if(StringUtils.hasLength(company.getMealPackage())){
            VALUES("meal_package", "#{mealPackage, jdbcType=VARCHAR}");
        }
        if(null != company.getAddUser()){
            VALUES("add_user", "#{addUser, jdbcType=INTEGER}");
        }
        if(null != company.getShoworder()){
            VALUES("showorder", "#{showorder, jdbcType=INTEGER}");
        }
        if(null != company.getSuperId()){
            VALUES("super_id", "#{superId, jdbcType=INTEGER}");
        }
        if(null != company.getRegisterDate()){
            VALUES("register_date", "#{registerDate, jdbcType=TIMESTAMP}");
        }
        if(null != company.getAbateDate()){
            VALUES("abate_date", "#{abateDate, jdbcType=TIMESTAMP}");
        }
        if(null != company.getAddDate()){
            VALUES("add_date", "#{addDate, jdbcType=TIMESTAMP}");
        }

        return SQL();
    }

    public String updateSelective(Subcompany company){

        BEGIN();
        UPDATE("subcompany");

        if(StringUtils.hasLength(company.getAddress())){
            SET("address=#{address, jdbcType=VARCHAR}");
        }
        if(null != company.getComNature()){
            SET("com_nature=#{comNature, jdbcType=INTEGER}");
        }
        if(null != company.getComSize()){
            SET("com_size=#{comSize, jdbcType=INTEGER}");
        }
        if(StringUtils.hasLength(company.getEmail())){
            SET("email=#{email, jdbcType=VARCHAR}");
        }
        if(StringUtils.hasLength(company.getFullname())){
            SET("fullname=#{fullname, jdbcType=VARCHAR}");
        }
        if(StringUtils.hasLength(company.getIndustry())){
            SET("industry=#{industry, jdbcType=VARCHAR}");
        }
        if(StringUtils.hasLength(company.getShortname())){
            SET("shortname=#{shortname, jdbcType=VARCHAR}");
        }
        if(StringUtils.hasLength(company.getTelephone())){
            SET("telephone=#{telephone, jdbcType=VARCHAR}");
        }
        if(StringUtils.hasLength(company.getMealPackage())){
            SET("meal_package=#{mealPackage, jdbcType=VARCHAR}");
        }
        if(null != company.getShoworder()){
            SET("showorder=#{showorder, jdbcType=INTEGER}");
        }
        if(null != company.getSuperId()){
            SET("super_id=#{superId, jdbcType=INTEGER}");
        }
        if(null != company.getAbateDate()){
            SET("abate_date=#{abateDate, jdbcType=TIMESTAMP}");
        }
        WHERE("id = #{id,jdbcType=INTEGER}");
        return SQL();
    }
}
